<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
  <script>
    $.extend({
      myTrim: function (str, type) {
        var reg = /^\s+|\s+$/g;
        var leftReg = /^\s*/;
        var rightReg = /(\s*$)/g;
        var allReg = /\s+/g;
        if (!type) {
          str = str.replace(reg, '');
        } else if (type === 'left') {
          str = str.replace(leftReg, '');
        } else if (type === 'right') {
          str = str.replace(rightReg, '');
        } else if (type === 'all') {
          str = str.replace(allReg, '');
        }
        return str
      },
      myToCamel: function(str, type) {
        type = type || '_';
        var reg = type === '_' ? /\_(\w)/g : /\-(\w)/g;
        return str.replace(reg, function($1, $2) {
          console.log(arguments);
          return $2.toUpperCase();
        })
      }
    });

    'user-name'
    'userName'
    'user_name'
  </script>
</body>

</html>